package com.example.mystoryapp2.adapter

import android.util.Log
import android.view.View
import android.widget.LinearLayout
import android.widget.TextView
import com.example.mystoryapp2.R
import com.example.mystoryapp2.domain.Story
import com.example.mystoryapp2.ui.base.BaseListAdapter
import com.example.mystoryapp2.ui.base.BaseViewHolder

class StoryListAdapter(private val list: ArrayList<Story>) :
    BaseListAdapter<Story, StoryListAdapter.StoryViewHolder>(list) {

    private val TAG = "StoryListAdapter"
    override fun getLayoutId(): Int {
        Log.d(TAG, "getLayoutId: + layout")
        return R.layout.item_story_list_layout;
    }

    class StoryViewHolder(itemView:View):BaseViewHolder(itemView){
        val mTvTitle: TextView = itemView.findViewById(R.id.tvTitle)
        val mTvDescription: TextView = itemView.findViewById(R.id.tvDescription)
        private val mLlContent: LinearLayout = itemView.findViewById(R.id.llItem)
        override fun getViewList(): List<View> {
            val arrayList = ArrayList<View>()
            arrayList.add(mTvDescription)
            arrayList.add(mTvTitle)
            arrayList.add(mLlContent)
            return arrayList
        }
    }

    override fun createViewHolder(itemView: View): StoryViewHolder {
        return StoryViewHolder(itemView)
    }

    override fun onBaseBindViewHolder(holder: StoryViewHolder, position: Int) {
        holder.mTvTitle.text = list[position].getTitle()
        holder.mTvDescription.text = list[position].getDescription()
//        holder.mLlContent.setOnClickListener {
//            Log.d(TAG, "onBindViewHolder: " + list[position].getStoryId())
//        }
        Log.d(TAG, "onBindViewHolder: " + holder.mTvTitle.text)
        Log.d(TAG, "onBindViewHolder: " + holder.mTvDescription.text)
    }

}

